//package com.pubinfo.passbook.data.quartz.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.pubinfo.passbook.common.entity.*;
//import com.pubinfo.passbook.common.mapper.TMdmSupplierBankMapper;
//import com.pubinfo.passbook.common.mapper.TMdmSupplierMapper;
//import com.pubinfo.passbook.common.mapper.TSourceInvoiceItemMapper;
//import com.pubinfo.passbook.common.mapper.TSourceInvoiceMapper;
//import com.pubinfo.passbook.common.model.bo.invoice.ScanEnvironmentalResult;
//import com.pubinfo.passbook.common.model.bo.mdm.SupplierBankParam;
//import com.pubinfo.passbook.common.model.bo.witeoff.EnvironmentalOrGroupMembershipDuesDTO;
//import com.pubinfo.passbook.common.model.bo.witeoff.InvoiceInfo;
//import com.pubinfo.passbook.common.model.ruler.UserAcc;
//import com.pubinfo.passbook.common.service.master.TInvoiceService;
//import com.pubinfo.passbook.common.service.mss.HttpService;
//import com.pubinfo.passbook.common.service.ruler.CheckService;
//import com.pubinfo.passbook.data.quartz.service.EnvironmentalAutoReimbursement;
//import lombok.SneakyThrows;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//
//import java.math.BigDecimal;
//import java.util.List;
//
//@Service
//public class EnvironmentalAutoReimbursementImpl implements EnvironmentalAutoReimbursement {
//  @Autowired
//  TMdmSupplierBankMapper bankMapper;
//  @Autowired
//  TMdmSupplierMapper supplierMapper;
//  @Autowired
//  TSourceInvoiceItemMapper invoiceMapper;
//
//  @Autowired
//  CheckService checkService;
//  @Autowired
//  TSourceInvoiceMapper sourceInvoiceMapper;
//  @Autowired
//  TInvoiceService invoiceService;
//  @Autowired
//  HttpService httpService;
//
//  @SneakyThrows
//  @Override
//  public void autoReimbursement() {
//    //查询没有报账的环保费
//    /**
//     * 污水处理费的报账分三种：
//     * 1、财政票据走“10040404行政事业社团收费”；
//     * 2、收款人非政府和自来水公司的发票走“10040701绿化环保”（暂不做自动报账）；
//     * 3、政府和自来水公司的发票走能耗集成“水费”（能耗系统暂不接入）。
//     */
//    //TODO 查询出多个没有报账的发票,后续需要过滤出已经报账的发票
//
//    List<ScanEnvironmentalResult> invoiceList = invoiceMapper.scanEnvironmental();
//    //对同一识别号的发票进行分组,
//    if (!CollectionUtils.isEmpty(invoiceList)) {
//      //根据发票查询纳税人识别号,再根据识别号查询mdm供应商数据,再由供应商关联到TMdmSupplierBank.如果一个发票查询出多个TMdmSupplierBank,则不进行自动报账.
//      //先查询省税务发票有没有没有报账的发票,
//      for (ScanEnvironmentalResult result : invoiceList) {
//        List<TMdmSupplierBank> supplierBankList = bankMapper.findSupplierBank(new SupplierBankParam(result));
//        if (!CollectionUtils.isEmpty(supplierBankList) && supplierBankList.size() == 1 && result.getJe().compareTo(new BigDecimal(50000)) < 1) {
//          //如果金额大于50000，则走人工
//          //查询发票报账所属公司是上市，还是存续。  参数gfsbh,返回 上市or存续 ,查询公司表nsrsbh，判断条件A开头是上市，B开头是存续，其他的返回0
//          TMdmSupplierBank supplierBank = supplierBankList.get(0);
//          String sapCompayCode = sourceInvoiceMapper.selectCompanyType(result.getGfsbh());
//          //其他类型的不进报账
//          if (!"0".equals(sapCompayCode)) {
//            QueryWrapper<TMdmSupplier> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("zregco", result.getXfsbh());
//            //查询供应商，如果查不到，或者条数大于1，则不报账。
//            List<TMdmSupplier> suppliers = supplierMapper.selectList(queryWrapper);
//            if (!CollectionUtils.isEmpty(suppliers) && suppliers.size() == 1) {
//              //  List<TWiteoffInvoiceInfo> invoiceInfos = new ArrayList<>();
//
//              InvoiceInfo invoiceInfo = sourceInvoiceMapper.invoiceInfoById(result.getId());
//              TMdmSupplier supplier = suppliers.get(0);
//              //   TWiteoffInvoiceInfo witeoffInvoiceInfo = new TWiteoffInvoiceInfo(supplier, invoiceInfo, 0);
//              //       invoiceInfos.add(witeoffInvoiceInfo);
//              // 0代表是环保费
//              UserAcc userAcc = checkService.getUserAcc("33034555@ZJ");
//              EnvironmentalOrGroupMembershipDuesDTO dto = new EnvironmentalOrGroupMembershipDuesDTO(null, 0, supplier, sapCompayCode, userAcc);
//              //发起自动报账
//              httpService.environmentalAutoCreateWriteoff(dto);
//
//            }
//
//          }
//        }
//
//      }
//
//    }
//
//  }
//}
